//
//  UIBarButtonItem+Extension.swift
//  SinaWB_XY
//
//  Created by 小熊猫 on 15/10/10.
//  Copyright © 2015年 小熊猫. All rights reserved.
//

import Foundation
import UIKit

extension UIBarButtonItem{
    
    class func item(imageName:String="",titleName:String="",target: AnyObject?,action: Selector)->UIBarButtonItem{
        let btn = UIButton()
        //给按钮设置图片
        if imageName.characters.count > 0{
        btn.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        btn.setImage(UIImage(named: "\(imageName)_highlighted"), forState: UIControlState.Highlighted)
        }
        
        //设置title
        if titleName.characters.count>0{
            btn.setTitle(titleName, forState: UIControlState.Normal)
            btn.titleLabel?.font=UIFont.systemFontOfSize(16)
            btn.setTitleColor(UIColor.grayColor(), forState: UIControlState.Normal)
            btn.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Highlighted)
        }
        
        //给按钮添加点击事件
        btn.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        
        
        btn.sizeToFit()
        return UIBarButtonItem(customView: btn)
    }
    
}